// ==================== src/error.rs ====================
//! 存储层错误定义

use thiserror::Error;
use nacos_core::NacosError;

/// 存储层错误类型
#[derive(Debug, Error)]
pub enum StorageError {
    #[error("连接错误: {0}")]
    Connection(String),
    
    #[error("序列化错误: {0}")]
    Serialization(#[from] serde_json::Error),
    
    #[error("IO错误: {0}")]
    Io(#[from] std::io::Error),
    
    #[error("数据库错误: {0}")]
    Database(String),
    
    #[error("事务错误: {0}")]
    Transaction(String),
    
    #[error("键已存在: {0}")]
    KeyExists(String),
    
    #[error("键不存在: {0}")]
    KeyNotFound(String),
    
    #[error("数据格式错误: {0}")]
    DataFormat(String),
    
    #[error("配置错误: {0}")]
    Config(String),
    
    #[error("未知错误: {0}")]
    Unknown(String),
}

impl From<StorageError> for NacosError {
    fn from(err: StorageError) -> Self {
        NacosError::Storage(err.to_string())
    }
}